﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList2.Items.Add("福建");
                DropDownList2.Items.Add("浙江");
                DropDownList2.Items.Add("江苏");
                DropDownList3.Items.Add("福州");
                DropDownList3.Items.Add("厦门");
                DropDownList3.Items.Add("泉州");
            }
        }

        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            string province = DropDownList2.SelectedValue;
            DropDownList3.Items.Clear();

            if (province == "福建")
            {
                DropDownList3.Items.Add("福州");
                DropDownList3.Items.Add("厦门");
                DropDownList3.Items.Add("泉州");
            }
            else if (province == "浙江")
            {
                DropDownList3.Items.Add("杭州");
                DropDownList3.Items.Add("温州");
                DropDownList3.Items.Add("嘉兴");
            }
            else
            {
                DropDownList3.Items.Add("苏州");
                DropDownList3.Items.Add("扬州");
                DropDownList3.Items.Add("徐州");
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
                if (FileUpload1.HasFile)
                {
                    string fileName = FileUpload1.FileName;
                    if (fileName.EndsWith(".jpg") || fileName.EndsWith(".jpeg"))
                    {
                        string path = Server.MapPath(@"~\img\" + fileName);
                        FileUpload1.SaveAs(path);
                        Image1.Visible = true;
                        Image1.ImageUrl = "~/img/" + fileName;
                    }
                    else
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "提示", "alert('图片格式不正确')", true);
                    }
                }
                else
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "提示", "alert('请提供上传文件')", true);
                }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            string sex = "";
            foreach (ListItem item in DropDownList1.Items)
            {
                if (item.Selected)
                {
                    sex = $"{item.Text}";
                }
            }
            string like = "";
            for (int i = 0; i < CheckBoxList1.Items.Count; i++)
            {
                if (CheckBoxList1.Items[i].Selected)
                {
                    like += CheckBoxList1.Items[i].Text + "   ";
                }
            }
            this.Label1.Text = $"用户名：{TextBox1.Text},性别：{sex},爱好：{like},我来自{DropDownList2.SelectedValue}省,{DropDownList3.SelectedValue}市,其他信息：{TextBox3.Text},头像：{Image1.ImageUrl}";

        }
    }
}